package com.cl.es.biz;

import com.cl.es.dao.StudentRepository;
import com.cl.es.po.Student;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: springdata
 * @description:
 * @author: 陈英俊
 * @create: 2022-03-07 15:52
 */
@RestController
@RequestMapping("/es")
public class EsBiz {


    @Autowired
    private RestHighLevelClient restHighLevelClient; // 原生


    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate; // spring data es  已弃用


    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;// spring data es
    @Autowired
    private ElasticsearchOperations elasticsearchOperations;// spring data es
    @Autowired
    private ElasticsearchRepository elasticsearchRepository;

    @Autowired
    private StudentRepository studentRepository;


    /**
     * org.elasticsearch.client.RestHighLevelClient  原生
     * org.springframework.data.elasticsearch.core.ElasticsearchTemplate  弃用
     * org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
     * org.springframework.data.elasticsearch.core.ElasticsearchOperations
     * ElasticsearchOperations 的 实现类 是 ElasticsearchRestTemplate
     * spring.io曰: springdataes  应该使用更级别的ElasticSearchOperations 和  ElasticSearchRepositories;
     * <p>
     * ElasticSearchOperations的
     * 实现一: ElasticsearchRestTemplate
     * 实现二: ElasticsearchTemplate 已经被弃用
     * </p>
     * <p>
     * dao:一般我们的dao可以继承ElasticSearchRepositories ;
     * </p>
     */


    @GetMapping("/01")
    public void get01() {
        Student student = new Student();
        student.setId(111L);
        student.setName("1陈亮1");
        studentRepository.save(student);
    }

    @GetMapping("/02")
    public void get02() {

        System.out.println(studentRepository.findById(111L));
    }
}
